﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using viWiki.Classes;
using viWiki.Controllers;

public partial class ClientScripts_viWiki_Wiki : System.Web.UI.Page
{    
    protected void Page_Load(object sender, EventArgs e)
    {
        List<NamespaceInfo> namespaces = NamespaceController.GetNamespaces();
        Namespaces.DataSource = namespaces;
        Namespaces.DataBind();
        BindWikiPages(namespaces);       
    }

    private void BindWikiPages(List<NamespaceInfo> namespaces)
    {
        StringBuilder sb = new StringBuilder();
        foreach (NamespaceInfo nspace in namespaces)
        {
            List<WikiPage> wikipages = WikiPageController.GetWikiPagesByNamespace(nspace.NamespaceInfoId);
            sb.Append("<select onchange=\"onWikiPageChanged()\" style=\"width: 98%; height: 200px;\" class=\"WikiPagesList\" multiple=\"true\" id=\"" + nspace.NamespaceInfoId + "\">");
            foreach (WikiPage wikipage in wikipages)
            {
                sb.Append("<option class=\"WikiPageItem\" value=\"" + wikipage.WikiPageId.ToString() + "\">" + wikipage.Name + "</option>");
            }            
            sb.Append("</select>");
        }
        LiteralControl list = new LiteralControl(sb.ToString());
        WikiPagesContainer.Controls.Add(list);
    }
}

